package cn.wu.jishupeizhi.service.impl;

import cn.wu.jishupeizhi.mapper.WhopListMapper;
import cn.wu.jishupeizhi.pojo.WhopList;
import cn.wu.jishupeizhi.service.WhopListService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author AndyWu
 * @version 1.0
 * @date 2025/2/8 10:22
 */
@Slf4j
@Service
public class WhopListServiceImpl implements WhopListService {

    @Autowired
    private WhopListMapper whopListMapper;


    @Override
    @Cacheable(cacheNames = "whoplist")
    public List<WhopList> getWhopAll() {
        List<WhopList> whopLists = whopListMapper.selectList(null);
        return whopLists;
    }

    @Override
    @Cacheable(cacheNames = "whoplist",key = "#id")
    public WhopList getWhopById(Integer id) {
        WhopList whopList = whopListMapper.selectById(id);
        if (whopList != null) {
            log.info("查询数据库id"+id.toString());
            return whopList;
        }
        return null;
    }

    @Override
    public WhopList getWhopById1(Integer id) {
        WhopList whopList = whopListMapper.selectById(id);
        if (whopList != null) {
            log.info("查询数据库id"+id.toString());
            return whopList;
        }
        return null;
    }
    @Override
    @Cacheable(cacheNames = "whoplist",key = "#email")
    public List<WhopList> getWhopByUser(String email) {
        QueryWrapper<WhopList> queryWrapper = new QueryWrapper<>();
        queryWrapper.like("email",email);
        List<WhopList> whopLists = whopListMapper.selectList(queryWrapper);
        if (whopLists != null) {
            log.info("查询数据库email"+email);
            return whopLists;
        }
        return List.of();
    }


}
